var fs=require("fs");
 /*
 异步读取文件夹
  fs.readdir("./",function (err,files) {
  console.log(files);
  });
 * */
 
/*
 同步读取文件
 console.log(fs.readdirSync("./1"));
* */

/*fs.readdir("./",function (err,files) {
    files.forEach(function (val, index, arr) {
      fs.stat(val,function (err2, stats) {

          if(stats.mode==33206){ //判断文件是文件夹 还是文件 如果为33206是文件 为16822是一个文件夹。
              console.log(val+"是一个文件")
          }else if(stats.mode==16822){
              console.log(val+"是一个文件夹")
          }

      })
    })
   /!* console.log(files);*!/
});*/


/*
var cStream=fs.createWriteStream("./3.txt");


cStream.write("hello");

cStream.end();
cStream.on("finish",function () {
    console.log("文件写入成功！")
});
cStream.on("error",function () {
    console.log("文件写入失败！")
})*/
/*var readStream=fs.createReadStream("./3.txt");
var data="";
readStream.on("data",function (chunk) {
    data+=chunk;
});

readStream.on("end",function () {
    console.log(data); 
});
readStream.on("error",function () {
    console.log("文件读取失败");
});*/


var writeStream=fs.createWriteStream("./2.txt");

var readStream=fs.createReadStream("./3.txt");

readStream.pipe(writeStream);
